package com.example.boot.dlshop.service.impl;

import com.example.boot.dlgoods.dao.DlGoodsMapper;
import com.example.boot.dlgoods.model.DlGoods;
import com.example.boot.dlgoodspic.dao.DlGoodsPicMapper;
import com.example.boot.dlgoodsss.dao.DlGoodsSsMapper;
import com.example.boot.dlorder.dao.DlOrderMapper;
import com.example.boot.dlorderevaluate.dao.DlOrderEvaluateMapper;
import com.example.boot.dlshop.dao.DlShopMapper;
import com.example.boot.dlshop.model.DlShop;
import com.example.boot.dlshop.service.DlShopService;
import com.example.boot.dlshop.vo.DlShopVo;
import com.example.boot.util.PicURLEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DlShopImpl implements DlShopService {

	@Autowired
	private DlShopMapper dlShopMapper;
	@Autowired
	private DlGoodsMapper dlGoodsMapper;
	@Autowired
	private DlGoodsPicMapper dlGoodsPicMapper;
	@Autowired
	private DlGoodsSsMapper dlGoodsSsMapper;
	@Autowired
	private DlOrderEvaluateMapper dlOrderEvaluateMapper;
	@Autowired
	private DlOrderMapper dlOrderMapper;
	@Autowired
	private PicURLEntity picURLEntity;

	@Override
	public DlShopVo byIdFindShop(String shopId, String adminId) throws Exception {
		DlShopVo vo = new DlShopVo();
		DlShop selectByPrimaryKey = dlShopMapper.selectByPrimaryKey(shopId);
		List<DlGoods> byShopFindAllGoods = dlGoodsMapper.byShopFindAllGoods(adminId);
		for (DlGoods gs : byShopFindAllGoods) {
			String goodsId = gs.getId();
			gs.setScore(dlOrderEvaluateMapper.findByGoodsEvaluate(goodsId));
			gs.setDescribeScore(dlOrderEvaluateMapper.findByDescribeScoreScoreGoodsEvaluate(goodsId));
			gs.setQualityScore(dlOrderEvaluateMapper.findByQualityScoreGoodsEvaluate(goodsId));
			gs.setPictureStr(picURLEntity.getUrlPrefix()+gs.getPictureStr());
			gs.setSalesVolume(dlOrderMapper.byGoodsIdFindSum(goodsId));
		}
		selectByPrimaryKey.setShopPictrue(picURLEntity.getUrlPrefix()+selectByPrimaryKey.getShopPictrue());
		vo.setModelList(byShopFindAllGoods);
		vo.setShop(selectByPrimaryKey);
		return vo;
	}

}
